﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.ObjectModel;
using NetBay.Core.BusinessEntities;
using System.ComponentModel;

namespace Rio.Framework.Pages.ChildWindows
{
    public partial class SelectionRecipientIndexChildWindow : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler  PropertyChanged;

        private Index _selectedIndex;
        private long _selectedIndexIdentifier;

        public ObservableCollection<Index> Indexes
        {
            get { return (ObservableCollection<Index>)GetValue(IndexesProperty); }
            set { SetValue(IndexesProperty, value); }
        }
        public static readonly DependencyProperty IndexesProperty = 
            DependencyProperty.Register("Indexes", typeof(ObservableCollection<Index>), typeof(SelectionRecipientIndexChildWindow), new PropertyMetadata(null));

        public Index SelectedIndex
        {
            get { return _selectedIndex; }
            set
            {
                _selectedIndex = value;
                OnPropertyChanged("SelectedIndex");
            }
        }

        public long SelectedIndexIdentifier
        {
            get { return _selectedIndexIdentifier; }
            set
            {
                _selectedIndexIdentifier = value;
                OnPropertyChanged("SelectedIndexIdentifier");

                SelectedIndex = Indexes.Where(index => index.Indentifier == _selectedIndexIdentifier).SingleOrDefault();
            }
        }

        public SelectionRecipientIndexChildWindow()
        {
            InitializeComponent();
        }

        private void validateButton_Click(object sender, RoutedEventArgs e)
        {
            DialogResult = true;
            this.Close();
        }

        private void cancelButton_Click(object sender, RoutedEventArgs e)
        {
            DialogResult = false;
            this.Close();
        }

        /// <summary>
        /// Called when [property changed].
        /// </summary>
        /// <param name="propertyName">Name of the property.</param>
        private void OnPropertyChanged(string propertyName)
        {
            if (this.PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
    }
}
